﻿Imports Microsoft.VisualStudio.DebuggerVisualizers
Imports System.Collections.Generic
Imports System.Data.Objects
Imports System.Windows.Forms

<Assembly: DebuggerVisualizer(GetType(ObjectQueryVisualizer), GetType(ObjectQueryVisualizerObjectSource), _
 Target:=GetType(ObjectQuery), Description:="ObjectQuery visualizer")> 

Public Class ObjectQueryVisualizer
    Inherits DialogDebuggerVisualizer


    Protected Overrides Sub Show(ByVal windowService As IDialogVisualizerService, ByVal objectProvider As IVisualizerObjectProvider)

        Dim ds As New DataSet()
        ds.ReadXml(objectProvider.GetData(), XmlReadMode.ReadSchema)

        Dim dtValues As DataTable = ds.Tables(Constants.TABLE_VALUES)
        Dim dtAddedValues As DataTable = ds.Tables(Constants.TABLE_ADDED)

        Using form As New ObjectQueryVisualizerForm
            form.dgvData.DataSource = dtValues
            For i As Integer = 2 To form.dgvData.Columns.Count - 1 Step 2
                ' hide columns with changeState
                ' the grid will show the state on the datacolumn by formatting it
                form.dgvData.Columns(i).Visible = False
            Next

            If (dtAddedValues.Rows.Count = 0) Then
                form.SplitContainer1.Panel2Collapsed = True
            Else
                form.dgvAddedData.DataSource = dtAddedValues
                For i As Integer = 2 To form.dgvAddedData.Columns.Count - 1 Step 2
                    ' hide columns with changeState
                    ' the grid will show the state on the datacolumn by formatting it
                    form.dgvAddedData.Columns(i).Visible = False
                Next
            End If

            Utility.InitStatesGrid(form.dgvStates, ds)

            form.lblCount.Text = String.Format("{0} entities + {1} added entities", _
                                               dtValues.Rows.Count, dtAddedValues.Rows.Count)
            form.tbTraceString.Text = ds.ExtendedProperties(Constants.EXT_PROP_TRACESTRING).ToString()
            form.ShowDialog()
        End Using
    End Sub

End Class
